<!--企业安全环保基本信息表 compan-->
<template>
  <Layout>
    <Form ref="queryForm" :model="dataToQuery" :label-width="120">
      <Row class="query-form">
        <Col span="8">
          <FormItem label='所属企业：'>
            <cascaderDom class="query-form-el" ref="groupOrg1" style="width: 100%;"
                         @setOrgInfo='setOrgId'
                         @setOrgname='setOrgName'
                         :orgTree="true"></cascaderDom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='归属地区：'>
            <Select v-model="dataToQuery.attriErea">
              <Option v-for="item in areaTreeMap['0']" :value="item.value" :key="item.value">{{ item.label }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-if="!switchFlag">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reseter" class="ivu-btn-reset">重置</Button>
          <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
        <Col span="8" v-else>
          <FormItem label='安全文化示范企业级别：'>
            <Select multiple v-model="safeLevels">
              <Option v-for="item in safeLevelList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label='安全生产标准化等级：'>
            <Select filterable v-model="safeRanks" multiple>
              <Option v-for="item in stdRankList" :value="item.codingCodeId"
                      :key="item.codingCodeId">{{ item.codingName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='职业健康体系认证：'>
            <Select class="query-form-el" v-model="dataToQuery.health" style="width: 100%;">
              <Option v-for="item in isPullateList" :value="item.value"
                      :key="item.value">{{ item.name }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='环境管理体系认证：'>
            <Select class="query-form-el" v-model="dataToQuery.manage" style="width: 100%;">
              <Option v-for="item in isPullateList" :value="item.value"
                      :key="item.value">{{ item.name }}
              </Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label='是否重点排污单位：' prop='isPullate'>
            <Select class="query-form-el" v-model="dataToQuery.isPullate" style="width: 100%;">
              <Option v-for="item in isPullateList" :value="item.value"
                      :key="item.value">{{ item.name }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="二级集团：">
            <Select v-model="dataToQuery.twoLevelOrgId" @on-change="selectTwoLevelOrg" clearable multiple
                    :max-tag-count="1">
              <Option v-for="item in twoOrgList" :value="item.orgId" :key="item.orgId">{{ item.orgName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reseter" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
          <Button type="primary" class="ivu-btn-add" :loading="buttonLoading" icon="md-cloud-download"
                  @click="downloadFile">导出
          </Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
           :loading='pageStatus.loading ||  pageStatus.baseLoading'
           border :columns="columns1" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange1"
              @on-page-size-change="pageSizeChange1" :page-size-opts="pageSizeArray" show-total show-sizer
              show-elevator/>
      </Col>
    </Row>
    <Modal :title="mode == 'view' ?'企业安全环保基本信息详情':'企业安全环保基本信息'" :transfer=false :mask-closable="false"
           v-model="dialogShow" v-if="dataToView && dialogShow" :width=1000 :styles="{height:'559px'}"
           class-name='limit-height-dialog'>
      <Row>
        <Col span="24">
          <Form ref="dataToView" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false"
                :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"
                :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='所属集团：'>
                  <div v-if="mode === 'view'">{{ dataToView.groupComName }}</div>

                  <Input v-else class='' type='text' v-model='dataToView.groupComName' :readonly="true"></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='企业名称：' prop='companyName'>
                  <div v-if="mode === 'view'">{{ dataToView.companyName }}</div>
                  <!--    <Input v-else class=''placeholder="请选择企业名称" type='text' v-model='dataToView.companyName' :readonly="true" @on-focus="openSelect"></Input>-->
                  <cascaderDom v-else class="query-form-el" ref="groupOrg"
                               @setOrgInfo='setOrgInfo'
                               @setOrgname='(data)=>{cascaderDomNameChangeHandle(data,"companyName");}'
                               :currentOrgId="dataToView.companyOrgId"
                               :setCurrentName="{label:dataToView.companyName, value:dataToView.companyOrgId}"
                               :orgTree="true"></cascaderDom>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='归属地区：' prop='attriErea'>
                  <div v-if="mode === 'view'">{{ areaCodeToAreaName(dataToView.attriErea) }}</div>
                  <Cascader v-else :data="tempAreaTree" v-model="dataToView.attriEreaArr" change-on-select
                            :transfer="true"
                            :load-data="areaTreeLoadData" :render-format="labels=>labels.join('·')" :clearable='false'
                            @on-change="(value,selectedData)=>{$set(dataToView,'attriErea',value.join(','))}"></Cascader>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='法人代表：' prop='legalName'>
                  <div v-if="mode === 'view'">{{ dataToView.legalName }}</div>
                  <Input v-else class='' placeholder="请填写法人代表" type='text' v-model='dataToView.legalName'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='单位从业人数：' prop='staffNumber'>
                  <div v-if="mode === 'view'">{{ dataToView.staffNumber }}</div>
                  <InputNumber v-else class='w' placeholder="请填写单位从业人数" :min="0" type='text'
                               v-model='dataToView.staffNumber'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='行业：' prop='industry'>
                  <div v-if="mode === 'view'">{{ dataToView.industry }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写行业" type='text' v-model='dataToView.industry'></Input>-->
                  <Select v-else filterable v-model="dataToView.industryId" @on-change="selectstdIndustry"
                          :label-in-value="true" placeholder="请选择行业" :clearable='true'>
                    <Option v-for="item in industryList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='是否重点排污单位：' prop='isPullate'>
                  <div v-if="mode === 'view'">{{ dataToView.isPullate == '0' ? '是' : '否' }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写是否重点排污单位" type='text' v-model='dataToView.isPullate'></Input>-->
                  <Select v-else class="query-form-el" placeholder="请选择是否重点排污单位" v-model="dataToView.isPullate"
                          :clearable='true'>
                    <Option v-for="item in isPullateList" :value="item.value"
                            :key="item.value">{{ item.name }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>

            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='安全部门负责人：'   prop='saPerson' >
                  <div v-if="mode === 'view'">{{ dataToView.saPersonName }}</div>
                  <!-- <Input v-else class='' placeholder="请填写安全管理机构" type='text' disabled v-model='dataToView.saPersonName'></Input> -->
                 <!-- <userDom v-else ref="saPersonDom" :selectData="saPerson" :singleChoice=true :ifUser="true"
                           :rootOrgName="user.companyName"
                           @setData='(data)=>{ if(data){this.$set(dataToView, "saPerson", data.userId), this.$set(dataToView, "saPersonName", data.userName),
                            this.$set(dataToView, "saPhone", data.mobileNumber)}}'></userDom> -->
				  <Select v-else class="query-form-el" v-model="dataToView.saPerson"
				    @on-change="(value)=>{personChange(value,'sa');}" >
				    <Option v-for="item in dictMap.saPerson" :value="item.userId"
				            :key="item.userId+item.companyName" :label='item.userName'>
							<span>{{ item.userName }}</span>
							<span style="float:right;color:#ccc">{{ item.companyName }}</span>
				    </Option>
				  </Select>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='安全部门负责人电话：' >
                  <div v-if="mode === 'view'">{{ dataToView.saPhone }}</div>
                  <Input v-else class='' placeholder="请填写安全管理机构" type='text' disabled v-model='dataToView.saPhone'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='环保部门负责人：'   prop='enPerson'>
                  <div v-if="mode === 'view'">{{ dataToView.enPersonName }}</div>
				  <!-- <Input v-else class='' placeholder="请填写安全管理机构" type='text' disabled v-model='dataToView.enPersonName'></Input> -->
                  <!-- <userDom v-else ref="enPersonDom" :selectData="enPerson" :singleChoice=true :ifUser="true"
                           :rootOrgName="user.companyName"
                           @setData='(data)=>{ if(data){this.$set(dataToView, "enPerson", data.userId), this.$set(dataToView, "enPersonName", data.userName),
                           this.$set(dataToView, "enPhone", data.mobileNumber)}}'></userDom> -->
				  <Select v-else class="query-form-el" v-model="dataToView.enPerson"
				    @on-change="(value)=>{personChange(value,'en');}">
				    <Option v-for="item in dictMap.enPerson" :value="item.userId"
				            :key="item.userId+item.companyName" :label='item.userName'>
							 <span>{{ item.userName }}</span>
							<span style="float:right;color:#ccc">{{ item.companyName }}</span>
				    </Option>
				  </Select>		   
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='环保部门负责人电话：' >
                  <div v-if="mode === 'view'">{{ dataToView.enPhone }}</div>
                  <Input v-else class='' placeholder="请填写安全管理机构" type='text' disabled v-model='dataToView.enPhone'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='生产许可证获得时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.safeLicence) }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写安全生产许可证及时限" type='text' v-model='dataToView.safeLicence'></Input>-->
                  <DatePicker v-else class="w" placeholder="请选择生产许可证获得时间" v-model='dataToView.safeLicence'></DatePicker>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='安全生产标准化等级：'>
                  <div v-if="mode === 'view'">{{ dataToView.safeRank }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写安全生产标准化等级" type='text' v-model='dataToView.safeRank'></Input>-->
                  <Select v-else filterable v-model="dataToView.safeRankId" @on-change="selectstdRank"
                          :label-in-value="true" placeholder="请选择安全生产标准化等级" :clearable='true'>
                    <Option v-for="item in stdRankList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='安全文化示范企业级别：'>
                  <div v-if="mode === 'view'">{{ dataToView.safeLevel }}</div>
                  <!--                                    <Input v-else class=''placeholder="请填写安全文化示范企业级别" type='text' v-model='dataToView.safeLevel'></Input>-->
                  <Select v-else filterable v-model="dataToView.safeLevelId" @on-change="selectSafeLevel"
                          :label-in-value="true" placeholder="请选择安全文化示范企业级别" :clearable='true'>
                    <Option v-for="item in safeLevelList" :value="item.codingCodeId"
                            :key="item.codingCodeId">{{ item.codingName }}
                    </Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='安全标准化达标时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.safeDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择安全标准化达标时间" v-model='dataToView.safeDate'></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='安全文化示范企业获得时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.exampleDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择安全文化示范企业获得时间"
                              v-model='dataToView.exampleDate'></DatePicker>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='职业健康体系认证时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.healthDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择职业健康体系认证时间" v-model='dataToView.healthDate'></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='环境管理体系认证时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.manageDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择环境管理体系认证时间" v-model='dataToView.manageDate'></DatePicker>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='安全管理机构：' prop="safeOrg">
                  <div v-if="mode === 'view'">{{ dataToView.safeOrg }}</div>
                  <Input v-else class='' placeholder="请填写安全管理机构" type='text' v-model='dataToView.safeOrg'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='环保管理机构：' prop="envOrg">
                  <div v-if="mode === 'view'">{{ dataToView.envOrg }}</div>
                  <Input v-else class='' placeholder="请填写环保管理机构" type='text' v-model='dataToView.envOrg'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='创建人：' prop='userName' v-if="mode === 'view'">
                  <div>{{ dataToView.userName }}</div>
                </FormItem>
              </Col>
            </Row>
			<Row type="flex" justify="space-around" class="code-row-bg">
			  <Col span="23">
			    <FormItem label='主营业务：'>
			      <div v-if="mode === 'view'">{{ dataToView.mainBusiness }}</div>
			      <Input v-else class='' placeholder="请填写环保管理机构" type='textarea'
                    maxlength="255" show-word-limit :autosize="{minRows:2,maxRows:5}" v-model='dataToView.mainBusiness'></Input>
			    </FormItem>
			  </Col>
			</Row>
          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dataToView')">确定</Button>
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
        <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
      </div>
    </Modal>
    <Modal title="安全标准化评级" :transfer=false footer-hide v-model="standardSelectModal" :width=900>
      <StandardSelect ref="selMission" @selectMission="selectStandard">
      </StandardSelect>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import StandardSelect from './SaStdStandardSelect.vue'
import {sessionStorage} from '@/common/cacheUtils.js';
import {formatDate} from '@/tools/index'
import {mapState} from 'vuex'
import pageCommonFunction from '@/components/pageCommonFunction.js'
// import userDom from "@/components/input-user.vue";

var cascaderDom = () => import('@/components/cascader-dom.vue');
export default {
  components: {
    cascaderDom, StandardSelect
	// , userDom
  },
  computed: {
    ...mapState('trhg', {
      areaMap: state => state.area.areaMap ? state.area.areaMap : [],
      areaTreeMap: state => state.area.areaTreeMap ? state.area.areaTreeMap : {},
    }),
  },
  data() {
    return {
      ...this.createCommonDataField(),
      user: sessionStorage('userId').getObject('userId'),
      saPerson: {},
      enPerson: {},
      safeRanks: [],
      safeLevels: [],
      twoOrgList: [],
      isPullateList: [
        {
          name: "是",
          value: "0"
        },
        {
          name: "否",
          value: "1"
        }
      ],
      switchFlag: false,
      stdRankList: [],
      columns1: [
        {title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
        {key: 'groupComName', title: '所属集团', minWidth: 150, align: 'center'},
        {key: 'companyName', title: '企业名称', minWidth: 150, align: 'center'},
        {
          key: 'attriErea', title: '归属地区', minWidth: 150, align: 'center', render: (h, params) => {
            return h('span', this.areaCodeToAreaName(params.row.attriErea));
          }
        },
        {key: 'legalName', title: '法人代表', minWidth: 150, align: 'center'},
        {key: 'staffNumber', title: '单位从业人数', minWidth: 150, align: 'center'},
        {key: 'industry', title: '行业', minWidth: 150, align: 'center'},
        {key: 'safeLicence', title: '生产许可证获得时间', minWidth: 200, align: 'center', render: this.renderCellDate},
        {
          key: 'isPullate', title: '是否重点排污单位', minWidth: 200, align: 'center', render: (h, params) => {
            return h('div', [params.row.isPullate === '0' ? '是' : '否']);
          }
        },
        {key: 'safeRank', title: '安全生产标准化等级', minWidth: 200, align: 'center'},
        {key: 'safeDate', title: '安全标准化达标时间', minWidth: 200, align: 'center', render: this.renderCellDate},
        {key: 'safeLevel', title: '安全文化示范企业级别', minWidth: 200, align: 'center'},
        {key: 'exampleDate', title: '安全文化示范企业获得时间', minWidth: 200, align: 'center', render: this.renderCellDate},
        {key: 'healthDate', title: '职业健康体系认证时间', minWidth: 200, align: 'center', render: this.renderCellDate},
        {key: 'manageDate', title: '环境管理体系认证时间', minWidth: 200, align: 'center', render: this.renderCellDate},
        {key: 'safeOrg', title: '安全管理机构', minWidth: 150, align: 'center'},
        {key: 'envOrg', title: '环保管理机构', minWidth: 150, align: 'center'},

        this.getActionColumns()
      ],
      ruleCustom: {
        groupComName: [{required: true, message: '请填写所属集团', trigger: 'change',}],
        companyName: [{required: true, message: '请填写企业名称', trigger: 'change',}],
        attriErea: [{required: true, message: '请填写归属地区', trigger: 'change',}],
        legalName: [{required: true, message: '请填写法人代表', trigger: 'change',}],
        saPerson: [{required: true, message: '请填写法人代表', trigger: 'change',}],
        enPerson: [{required: true, message: '请填写法人代表', trigger: 'change',}],
        saPhone: [{
          pattern: /^1[3456789]\d{9}$/,
          required: true,
          message: '请正确输入电话号',
          trigger: 'change',
        }],
        enPhone: [{
          pattern: /^1[3456789]\d{9}$/,
          required: true,
          message: '请正确输入电话号',
          trigger: 'change',
        }],
        staffNumber: [{
          pattern: /^([0-9][0-9]*)+(.[0-9]{1,4})?$/,
          required: true,
          message: '请填写单位从业人数必须为数字',
          trigger: 'change',
          type: 'number'
        }],
        industry: [{required: true, message: '请填写行业', trigger: 'change',}],
        safeLicence: [{required: true, message: '请填写安全生产许可证及时限', trigger: 'change',}],
        isPullate: [{required: true, message: '请填写是否重点排污单位', trigger: 'change',}],
        safeRank: [{required: true, message: '请填写安全生产标准化等级', trigger: 'change',}],
        safeDate: [{required: true, message: '请填写安全标准化达标时间', trigger: 'change', type: 'date'}],
        safeLevel: [{required: true, message: '请填写安全文化示范企业级别', trigger: 'change',}],
        exampleDate: [{required: true, message: '请填写安全文化示范企业获得时间', trigger: 'change', type: 'date'}],
        healthDate: [{required: true, message: '请填写职业健康体系认证时间', trigger: 'change', type: 'date'}],
        manageDate: [{required: true, message: '请填写环境管理体系认证时间', trigger: 'change', type: 'date'}],
        safeOrg: [{required: true, message: '请填写安全管理机构', trigger: 'change',}],
        envOrg: [{required: true, message: '请填写环保管理机构', trigger: 'change',}],

      },
      tableHeight: 10,
      industryList: [],
      safeLevelList: [],
      twoOrgInfo: [],
      // api
      standardSelectModal: false,
      queryUrl: Api.queryEnvInfoCompan,
      deleteUrl: Api.deleteEnvInfoCompan,
      updateUrl: Api.updateEnvInfoCompan,
      saveUrl: Api.saveEnvInfoCompan,
      buttonLoading: false,
	  dictMap:{}
    }
  },
  async mounted() {
    this.dataToQuery = {};
    this.setTableHeight();
    this.pageStatus.baseLoading = true;
    this.$http.get(Api.getTwoOrgInfo).then((res) => {
      this.twoOrgList = res.data.data;
    }).catch(e => {
      this.$Message.error("数据获取失败")
    });
    await this.$store.dispatch('trhg/area/query', {scope: this}, {root: true});
	await this.$http.get(Api.queryDictBycode+"SSL-000001,env-00001,env-00002",{}).then((res)=>{
		this.stdRankList = res.data.data['SSL-000001']
		this.industryList = res.data.data['env-00001']
	    this.safeLevelList = res.data.data['env-00002']
	})
    // this.$http.get(Api.quqeryTwoOrgInfo).then((res) => {
    //   this.twoOrgInfo = res.data.data;
    // });
    this.pageStatus.baseLoading = false
    this.query();
    this.tempAreaTree = this.areaTreeMap['0']
  },
  methods: {
    ...pageCommonFunction,
	async setOrgInfo(data){
		if (data && data instanceof Array && data.length > 0) {
			await this.getPerson(data[data.length - 1],this.dataToView.companyName)
		    this.$set(this.dataToView, 'companyOrgId', data[data.length - 1])
		}
	},
	personChange(value,type){
		this.dataToView[type+'Person'] = '';
		this.dataToView[type+'PersonName'] = '';
		this.dataToView[type+'Phone'] = '';
		this.dictMap[type+'Person'].forEach(v=>{
			if (v.userId == value) {
				this.dataToView[type+'Person'] = v.userId;
				this.dataToView[type+'PersonName'] = v.userName;
				this.dataToView[type+'Phone'] = v.mobileNumber;
			} 
		})
	},
	//获取安全环保企业负责人角色维护的公司人员
	async getPerson(companyId,companyName){
		this.dictMap= {
			saPerson: [],
			enPerson: []
		}
		await this.$http.get(Api.selectUserByRoleIdCompanyId+companyId+'?companyName='+companyName).then(res => {
			if (res.data.status === 200) {
				this.dictMap={
					saPerson: res.data.data.saPerson,
					enPerson: res.data.data.enPerson
				}
			}
		})
	},
     async beforeEditDialogOpen(data) {
		setTimeout(() => {
		 this.getPerson(data.row.companyOrgId,data.row.companyName)
		}, 100)
	 
      if (data.row.attriErea) {
        data.row.attriEreaArr = data.row.attriErea.split(',')
        data.row.companyAddressName = this.areaCodeToAreaName(data.row.attriErea)
      }
    },
    async afterDataToViewInit(data) {
		
      // this.saPerson = {name: this.dataToView.saPersonName}
      // this.enPerson = {name: this.dataToView.enPersonName}
      if (data && data.attriErea) {
        let companyAddressArr = data.attriErea.split(',')
        this.tempAreaTree = []
        setTimeout(() => {
          this.tempAreaTree = this.addressEditArr(this.areaTreeMap, companyAddressArr)
        }, 100)
      }
      setTimeout(() => {
		
        // this.$refs.saPersonDom.setCurrentInfo();
        // this.$refs.enPersonDom.setCurrentInfo();
      }, 100)
    },
    deleteData(params) {
      this.deleteDateById(params.row.companyInfoId);
    },
    deleteDataToView() {
      this.check()
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 88;

      } else {
        this.tableHeight = this.tableHeight - 88;
      }

    },
    setOrgId(data) {
      this.dataToQuery.companyOrgId = data[data.length - 1];
    },
    setOrgName(data) {

    },
    selectTwoLevelOrg(value) {
      this.dataToQuery.twoLevelOrgIds = value.join()
    },
    query() {


      this.dataToQuery.safeLevels = "";
      this.dataToQuery.safeRanks = "";

      this.safeRanks.forEach(item => {

        this.dataToQuery.safeRanks += item + ","
      });
      this.safeLevels.forEach(item => {

        this.dataToQuery.safeLevels += item + ","
      });

      this.query1()
    },
    selectSafeLevel(row) {
      this.dataToView.safeLevelId = row.value;
      this.dataToView.safeLevel = row.label;
    },
    selectstdRank(stdRank) {
      this.dataToView.safeRankId = stdRank.value;
      this.dataToView.safeRank = stdRank.label;
    },
    selectstdIndustry(row) {
      this.dataToView.industryId = row.value;
      this.dataToView.industry = row.label;
    },
    submit(name) {
      if (this.dataToView.safeRankId == null) {
        this.dataToView.safeRank = null
      }
      if (this.dataToView.safeLevelId == null) {
        this.dataToView.safeLevel = null
      }
      let att = this.areaCodeToAreaName(this.dataToView.attriErea);
      this.dataToView.attriEreaName = att;

      this.submitBase(name);
    },
    submitToDataToView() {
      this.check();
    },
    check() {
      let url = Api.checkEnvInfoComan;
      this.$http.get(url).then(res => {
        if (res.data.status == '200') {
          sessionStorage('envInfoComan').set('check', res.data.data);
        } else {
          sessionStorage('envInfoComan').set('check', '1');
        }
      }).catch(e => {
        sessionStorage('envInfoComan').set('check', '1');
        console.error(e);
        this.$Message.error('查询失败');
      })
    },
    async addInfo() {
      this.dataToView = (this.createEmptyDataToAdd instanceof Function) ? this.createEmptyDataToAdd() : {};
      this.dataToView.registrant = this.currentUser.userName;
      this.dataToView.registTime = new Date();
	  let userInfo = sessionStorage('userId').getObject('userId')
	  await this.getPerson(userInfo.companyId,userInfo.companyName)
      this.mode = 'add';
      this.dialogShow = true;
    },
    createEmptyDataToAdd() {
      return {
        companyOrgId: sessionStorage('userId').getObject('userId').companyId,
        companyName: sessionStorage('userId').getObject('userId').companyName,
        groupComId: sessionStorage('userId').getObject('userId').twoLevelOrgId,
        groupComName: sessionStorage('userId').getObject('userId').twoLevelOrgName,
        staffNumber: 0
      }
    },
    reseter() {
      this.safeRanks = [];
      this.safeLevels = [];
      this.dataToQuery = {};
      this.$refs.groupOrg1.resetCurrentOrg();
      this.query1()
    },
    downloadFile() {
      this.buttonLoading = true
      let orgId = sessionStorage('userId').getObject('userId').companyId
      let data = {
        orgId: orgId,
      };
      this.dataToQuery.safeLevels = "";
      this.dataToQuery.safeRanks = "";

      this.safeRanks.forEach(item => {

        this.dataToQuery.safeRanks += item + ","
      });
      this.safeLevels.forEach(item => {

        this.dataToQuery.safeLevels += item + ","
      });
      data = Object.assign(data, JSON.parse(JSON.stringify(this.dataToQuery)));
      this.$http.get(Api.downloadEnvInfoCompan, {
        params: data,
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = "企业基本信息(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading = false
      })
    },
    selectStandard(row) {
      this.standardSelectModal = false;
      this.dataToView.companyOrgId = row.stdOrgId;
      this.dataToView.companyId = row.standardId;
      this.dataToView.companyName = row.stdOrgName;
      this.dataToView.safeRankId = row.stdRankId;
      this.dataToView.safeRank = row.stdRank;
      this.dataToView.attriErea = row.location;
      this.dataToView.safeDate = this.renderViewDate(row.appDate);

    },
    openSelect() {
      this.standardSelectModal = true
    },

  },
  watch: {},

}
</script>

<style lang='css' scoped>
@import '../../../index.css';
</style>
